home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / lha_axeman / patmatch.c < prev    next >
C/C++ Source or Header  |  1995-09-01  |  1KB  |  37 lines

  1. /*
  2.  *      Returns true if string s matches pattern p.
  3.  */
  4.  
  5. #include <ctype.h>
  6.  
  7. int
  8. patmatch(p, s, f)
  9. register char  *p;                                       /* pattern */
  10. register char  *s;                               /* string to match */
  11. int            f;                            /* flag for case force */
  12. {
  13.    char  pc;                     /* a single character from pattern */
  14.  
  15.    while (pc = ((f && islower(*p)) ? toupper(*p++) : *p++))
  16.       {
  17.       if (pc == '*')
  18.          {
  19.          do {                    /* look for match till s exhausted */
  20.             if (patmatch (p, s, f))
  21.                   return (1);
  22.             } while (*s++);
  23.          return (0);
  24.          }
  25.       else
  26.          if (*s == 0)
  27.             return (0);                       /* s exhausted, p not */
  28.          else
  29.             if (pc == '?')
  30.                s++;                       /* matches all, just bump */
  31.             else
  32.                if (pc != ((f && islower(*s)) ? toupper(*s++) : *s++))
  33.                   return (0);
  34.       }
  35.    return (!*s);            /* p exhausted, ret true if s exhausted */
  36. }
  37.